Skip to content

Upstream first batch of lemmas from Lido engagement#2787

Merged
automergerpr-permission-manager[bot] merged 7 commits into
masterfrom
upstream-lido-lemmas
Aug 19, 2025
Merged

Upstream first batch of lemmas from Lido engagement#2787
automergerpr-permission-manager[bot] merged 7 commits into
masterfrom
upstream-lido-lemmas

Conversation

@lucasmt
Copy link
Copy Markdown
Contributor

@lucasmt lucasmt commented Jul 28, 2025

Lemmas were taken from this file: https://github.com/runtimeverification/_audits_lidofinance_dual-governance_fork/blob/rv-extension-refactor-full-suite/test/kontrol/lido-lemmas.k. Not all of the lemmas have been included, as some of them require further analysis.

rule 0 <Int X => true requires 0 <=Int X andBool notBool (X ==Int 0) [simplification(60)]

rule X <=Int maxUInt256 => X <Int pow256 [simplification]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not entirely sure these three lemmas are strictly necessary. They seem to be things that the SMT solver could easily resolve, but maybe they can help trigger further simplifications.

andBool 0 <Int C
andBool A <Int ( C *Int B )
[simplification, symbolic(A, B), concrete(C), preserves-definedness]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a fairly specific lemma, but I suppose it might be worth having if we run into an expression like this again.


rule [notBool-or]: notBool ( A orBool B ) => ( notBool A ) andBool ( notBool B ) [simplification(60)]
rule [notBool-and]: notBool ( A andBool B ) => ( notBool A ) orBool ( notBool B ) [simplification(60)]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set a later priority for these rules so they don't conflict with the preceding ones.

#asWord ( B1 +Bytes B2 ) <Int X => #asWord ( B1 ) <Int X /Int ( 2 ^Int ( 8 *Int lengthBytes ( B2 ) ) )
requires X modInt ( 2 ^Int ( 8 *Int lengthBytes ( B2 ) ) ) ==Int 0
[simplification, preserves-definedness]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if too specific. I considered if it should use the concrete(X) attribute, but if it didn't include it in the first place it's probably because the expression that originally motivated it had a symbolic X.

rule [b2w-lt]:
bool2Word ( B:Bool ) *Int X <Int Y =>
( ( notBool B ) andBool 0 <Int Y ) orBool ( B andBool X <Int Y )
[simplification, concrete(Y)]
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the original file this had a typo, ( notBool B ) andBool 0 <=Int Y.

Comment on lines +94 to +96
X xorInt Y <Int Z => true
requires X <Int ( 2 ^Int log2Int ( Z ) ) andBool Y <Int ( 2 ^Int log2Int ( Z ) )
[simplification, concrete(Z)]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need an additional constraint for Z >Int 0 to avoid the log2Int undefinedness?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I'll add the constraint

@lucasmt lucasmt force-pushed the upstream-lido-lemmas branch from 2fdfcac to f432111 Compare August 1, 2025 15:08
@lucasmt lucasmt marked this pull request as ready for review August 1, 2025 15:14
Comment on lines +154 to +181
claim [zero-lt-sub]: <k> runLemma ( 0 <Int A -Int B ) => doneLemma ( B <Int A ) ... </k>
claim [zero-le-sub]: <k> runLemma ( 0 <=Int A -Int B ) => doneLemma ( B <=Int A ) ... </k>
claim [zero-gt-sub]: <k> runLemma ( 0 >Int A -Int B ) => doneLemma ( B >Int A ) ... </k>
claim [zero-ge-sub]: <k> runLemma ( 0 >=Int A -Int B ) => doneLemma ( B >=Int A ) ... </k>

claim [sub-gt-zero]: <k> runLemma ( A -Int B >Int 0 ) => doneLemma ( A >Int B ) ... </k>
claim [sub-ge-zero]: <k> runLemma ( A -Int B >=Int 0 ) => doneLemma ( A >=Int B ) ... </k>
claim [sub-lt-zero]: <k> runLemma ( A -Int B <Int 0 ) => doneLemma ( A <Int B ) ... </k>
claim [sub-le-zero]: <k> runLemma ( A -Int B <=Int 0 ) => doneLemma ( A <=Int B ) ... </k>

claim [mul-lt-const]: <k> runLemma ( 36 *Int B <Int 1728 ) => doneLemma ( B <Int 48 ) ... </k>
claim [mul-le-const]: <k> runLemma ( 36 *Int B <=Int 1728 ) => doneLemma ( B <=Int 48 ) ... </k>
claim [mul-gt-const]: <k> runLemma ( 36 *Int B >Int 1728 ) => doneLemma ( B >Int 48 ) ... </k>
claim [mul-ge-const]: <k> runLemma ( 36 *Int B >=Int 1728 ) => doneLemma ( B >=Int 48 ) ... </k>

claim [const-gt-mul]: <k> runLemma ( 1728 >Int 36 *Int B ) => doneLemma ( 48 >Int B ) ... </k>
claim [const-ge-mul]: <k> runLemma ( 1728 >=Int 36 *Int B ) => doneLemma ( 48 >=Int B ) ... </k>
claim [const-lt-mul]: <k> runLemma ( 1728 <Int 36 *Int B ) => doneLemma ( 48 <Int B ) ... </k>
claim [const-le-mul]: <k> runLemma ( 1728 <=Int 36 *Int B ) => doneLemma ( 48 <=Int B ) ... </k>

claim [eq-neg]: <k> runLemma ( A ==Int -1 ) => doneLemma ( false ) ... </k>
requires 0 <=Int A

claim [nonneg-and-nonzero]: <k> runLemma ( 0 <Int X ) => doneLemma ( true ) ... </k>
requires 0 <=Int X andBool notBool ( X ==Int 0 )

claim [le-maxuint256]: <k> runLemma ( X <=Int maxUInt256 ) => doneLemma ( X <Int pow256 ) ... </k>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These claims pass even without the corresponding lemmas, but only because the SMT solver can prove the implication. The lemmas are needed if we want to actually simplify the expressions.

@lucasmt lucasmt requested a review from anvacaru August 13, 2025 04:45
@automergerpr-permission-manager automergerpr-permission-manager Bot merged commit b2e84d1 into master Aug 19, 2025
12 checks passed
@automergerpr-permission-manager automergerpr-permission-manager Bot deleted the upstream-lido-lemmas branch August 19, 2025 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants